/*
 *
Refer to http://www.cplusplus.com/reference/clibrary/cstdlib/atof/

atof
function
<cstdlib>
double atof ( const char * str );
Convert string to double

Parses the C string str interpreting its content as a floating point number and returns its value as a double.

The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals, and interprets them as a numerical value. The rest of the string after the last valid character is ignored and has no effect on the behavior of this function.

A valid floating point number for atof is formed by a succession of:
An optional plus or minus sign
A sequence of digits, optionally containing a decimal-point character
An optional exponent part, which itself consists on an 'e' or 'E' character followed by an optional sign and a sequence of digits.
If the first sequence of non-whitespace characters in str does not form a valid floating-point number as just defined, or if no such sequence exists because either str is empty or contains only whitespace characters, no conversion is performed.

Parameters
str
C string beginning with the representation of a floating-point number.

Return Value
On success, the function returns the converted floating point number as a double value.
If no valid conversion could be performed, or if the correct value would cause underflow, a zero value (0.0) is returned.
If the correct value is out of the range of representable values, a positive or negative HUGE_VAL is returned.
 * 
 * */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float InvSqrt(float x)
{
	float xhalf = 0.5f*x;
	int i = *(int *)&x;
	i = 0x5f3759df - (i>>1);
	x = *(float *)&i;
	x = x*(1.5f-xhalf*x*x);
	return x;
}

int main(int argc,char** argv)
{
	float f_test;
	f_test = atof(argv[1]);
	printf("InvSqrt(%f)=%f\n",f_test,InvSqrt(f_test));

	return 0;
}
